package com.mindskip.xzs.controller.admin;

import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.dto.CorrectingDto;
import com.mindskip.xzs.service.CorrectingService;
import com.mindskip.xzs.service.impl.CorrectingServiceImpl;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("CorrectingController")
@RequestMapping(value = "/api/admin/correcting")
public class CorrectingController {
    private final CorrectingService correctingService;

    public CorrectingController(CorrectingService correctingService) {
        this.correctingService = correctingService;
    }

    //获取待批改的试卷列表
    //根据学科id查询
    @RequestMapping(value = "/getPendingPapers",method = RequestMethod.POST)
    public RestResponse<List<CorrectingDto>> getPendingPapers(@RequestParam(required = false) Integer subjectId){
        List<CorrectingDto> pendingPapers = correctingService.getPendingPapers(subjectId);
        return RestResponse.ok(pendingPapers);
    }

    //获取指定试卷的详细信息
    @RequestMapping(value = "/{paperId}",method = RequestMethod.POST)
    public RestResponse<CorrectingDto> getPaperDetail(@PathVariable Integer paperId){
        CorrectingDto paperDetail = correctingService.getPaperDetail(paperId);
        return RestResponse.ok(paperDetail);
    }
    //提交试卷批改结果
    @RequestMapping(value = "/{paperId}/grade")
    public RestResponse<String> gradePaper(@PathVariable Integer paperId,@RequestBody List<CorrectingDto> correctedAnswers){

        correctingService.gradePaper(paperId,correctedAnswers);
        return RestResponse.ok();
    }
}
